package com.example.config;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Component
public class MyInterceptor  implements HandlerInterceptor {
    @Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

    String uri= request.getRequestURI();
    Object loginName = request.getSession().getAttribute("aduName");
    if(uri.startsWith("/admin") && null == loginName){
        response.sendRedirect("/toLoginPage");
        return  false;
    }

    return true;
}
}

